package com.platform.base.service.impl;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.base.domain.*;
import com.platform.base.mapper.BaseLocationMapper;
import com.platform.base.mapper.CollectorInfoMapper;
import com.platform.base.mapper.ValveTypeMapper;
import com.platform.common.constant.UserConstants;
import com.platform.common.exception.BusinessException;
import com.platform.common.utils.DateUtils;
import com.platform.common.utils.StringUtils;
import com.platform.common.utils.netty.NettyUtil;
import com.platform.common.utils.rabbit.RabbitUtils;
import com.platform.common.utils.redis.RedisRun;
import com.platform.common.utils.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.platform.base.mapper.ValveInfoMapper;
import com.platform.base.service.IValveInfoService;
import com.platform.common.core.text.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 阀门信息Service业务层处理
 * 
 * @author wangqi
 * @date 2020-09-25
 */
@Service
public class ValveInfoServiceImpl extends ServiceImpl<ValveInfoMapper,ValveInfo> implements IValveInfoService
{
    @Autowired
    private ValveInfoMapper valveInfoMapper;
    @Autowired
    private CollectorInfoMapper collectorInfoMapper;

    @Autowired
    private ValveTypeMapper valveTypeMapper;

    @Autowired
    private BaseLocationMapper baseLocationMapper;

    @Autowired
    private RedisUtil redisUtil;


    @Autowired
    private RabbitUtils rabbitUtils;

    /**
     * 查询热信息列表
     *
     * @param locationId 热信息
     * @return 热信息
     */
    @Override
    public List<ValveInfo> selectValveInfoBylocationId(String locationId)
    {
        return valveInfoMapper.selectValveInfoBylocationId(locationId);
    }

    /**
     * 查询热信息列表
     *
     * @param collectorId 热信息
     * @return 热信息
     */
    @Override
    public List<ValveInfo> selectValveInfoBycollectorId(String collectorId)
    {
        return valveInfoMapper.selectValveInfoBycollectorId(collectorId);
    }
    /**
     * 查询热信息列表
     *
     * @return 热信息
     */
    @Override
    public List<ValveInfo> selectCollectorInfoEq()
    {
        return valveInfoMapper.selectCollectorInfoEq();
    }

    /**
     * 查询阀门信息列表
     * 
     * @param valveInfo 阀门信息
     * @return 阀门信息
     */
    @Override
    public List<ValveInfo> selectValveInfoList(ValveInfo valveInfo)
    {
        return valveInfoMapper.selectValveInfoList(valveInfo);
    }

    /**
     * 查询阀门信息
     *
     * @param valveId 阀门Id
     * @return 阀门信息集合
     */
    @Override
    public ValveInfo selectValveInfoById(String valveId){
        ValveInfo valveInfo = valveInfoMapper.selectValveInfoById(valveId);
        return valveInfo;
    }

    /**
     * 查询阀门信息
     *
     * @param valveId 阀门Id
     * @param collectorId 阀门Id
     * @return 阀门信息集合
     */
    @Override
    public ValveInfo selectValveInfoBytId(String valveId,String collectorId){
        ValveInfo valveInfo = valveInfoMapper.selectValveInfoBytId(valveId,collectorId);
        return valveInfo;
    }

    /**
     * 新增阀门信息
     * 
     * @param valveInfo 阀门信息
     * @return 结果
     */
    @Override
    public int insertValveInfo(ValveInfo valveInfo)
    {
        valveInfo.setCreateTime(DateUtils.getNowDate());
        return valveInfoMapper.insert(valveInfo);
    }

    /**
     * 修改阀门信息
     * 
     * @param valveInfo 阀门信息
     * @return 结果
     */
    @Override
    public int updateValveInfo(ValveInfo valveInfo)
    {
        valveInfo.setUpdateTime(DateUtils.getNowDate());
        return valveInfoMapper.updateById(valveInfo);
    }

    /**
     * 删除阀门信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteValveInfoByIds(String ids)
    {
        return valveInfoMapper.deleteValveInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 根据采集器ID更新阀门登记状态
     *
     * @param collectorId 采集器信息
     * @return 结果
     */
    @Override
    public int updateValveInfoByCollectorId(String collectorId){
        return valveInfoMapper.updateValveInfoByCollectorId(collectorId);
    }

    /**
     * 校验阀门是否唯一
     *
     * @param valveInfo 阀门信息
     * @return 结果
     */
    @Override
    public String checkValveUnique(ValveInfo valveInfo){
        ValveInfo info = valveInfoMapper.selectValveInfoBytId(valveInfo.getValveId().substring(valveInfo.getValveId().length()-4),valveInfo.getCollectorId());
        // selectById(valveInfo.getValveId());
        if (StringUtils.isNotNull(info))
        {
            return UserConstants.VALVE_ID_NOT_UNIQUE;
        }
        return UserConstants.VALVE_ID_UNIQUE;
    }

    /**
     * 导入采集器信息数据
     *
     * @param infoList 采集器信息数据
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @param operName 操作用户
     * @return 结果
     */
    @Override
    public String importInfo(List<ValveInfo> infoList, Boolean isUpdateSupport, String operName)
    {
        if (StringUtils.isNull(infoList) || infoList.size() == 0)
        {
            throw new BusinessException("导入阀门信息数据不能为空！");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (ValveInfo info : infoList)
        {
            try
            {
                //查询阀门类型信息
                ValveType type = null;
                if(info.getTypeName()!=null && !info.getTypeName().equals("")){
                    List<ValveType> list = valveTypeMapper.selectList(new QueryWrapper<ValveType>().eq("type_name", info.getTypeName()));
                    if(list!=null && list.size()>0){
                        type = list.get(0);
                        info.setTypeId(type.getTypeId());
                    }else{
                        failureNum++;
                        failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 阀门类型不存在");
                        continue;
                    }
                }
                //查询采集器地址信息
                BaseLocation location = null;
                if(info.getLocationName()!=null && !info.getLocationName().equals("")){
                    List<BaseLocation> list = baseLocationMapper.selectList(new QueryWrapper<BaseLocation>().eq("location_name", info.getLocationName()));
                    if(list!=null && list.size()>0){
                        location = list.get(0);
                        info.setLocationId(location.getLocationId());
                    }
                }
                // 校验采集器是否存在
                ValveInfo f = valveInfoMapper.selectById(info.getValveId());
                if (StringUtils.isNull(f))
                {
                    info.setCreateBy(operName);
                    info.setCreateTime(DateUtils.getNowDate());
                    this.insertValveInfo(info);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 导入成功");
                }
                else if (isUpdateSupport)
                {
                    info.setUpdateBy(operName);
                    info.setUpdateTime(DateUtils.getNowDate());
                    this.updateValveInfo(info);
                    successNum++;
                    successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 更新成功");
                }
                else
                {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 已存在");
                }
            }
            catch (Exception e)
            {
                failureNum++;
                String msg = "<br/>" + failureNum + "、阀门 " + info.getValveId() + " 导入失败：";
                failureMsg.append(msg + e.getMessage());
                log.error(msg, e);
            }
        }
        if (failureNum > 0)
        {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }
        else
        {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 阀门登记
     * @param valveIds 阀门信息
     * @param operName 操作用户
     * @return
     * @throws Exception
     */
    @Override
    public String registerInfo(String[] valveIds, String operName) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = valveInfoMapper.selectValveInfoById(valveId);
            CollectorInfo collectorInfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
            int ccount = collectorInfo.getValveCount();
            if(ccount>250){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门登记超过250个上限");
                continue;
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "03";
            //计算校验码
            int ll = NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " 00 00 00 00 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "阀门登记");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result.equals("00") || result.equals("01")){
                info.setRegisterFlag("1");
                info.setUpdateBy(operName);
                info.setUpdateTime(DateUtils.getNowDate());
                valveInfoMapper.updateById(info);
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 登记成功");
            }else{
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 登记失败");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，阀门登记失败！共 " + failureNum + " 条数阀门登记失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部登记成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 阀门注销
     * @param valveIds 阀门信息
     * @param operName 操作用户
     * @return
     * @throws Exception
     */
    @Override
    public String cancelInfo(String[] valveIds, String operName) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            valveId= valveId.substring(valveId.length()-4);
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "04";
            //计算校验码
            int ll = NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " 00 00 00 00 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "阀门注销");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result.equals("00") || result.equals("02")){
                info.setRegisterFlag("0");
                info.setUpdateBy(operName);
                info.setUpdateTime(DateUtils.getNowDate());
                valveInfoMapper.updateById(info);
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 注销成功");
            }else{
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 注销失败");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，阀门注销失败！共 " + failureNum + " 条阀门注销失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部登记成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 设置阀门开度
     * @param valveIds 阀门信息
     * @param hex 阀门开度值
     * @return
     * @throws Exception
     */
    @Override
    public String apertureInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "02";
            //计算校验码
            int ll = NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + hex + " 00 00 00 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "设置阀门开度");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(!result.equals("00")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 设置阀门开度失败");
            }else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 设置阀门开度成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，设置阀门开度失败！共 " + failureNum + " 条设置阀门开启失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部设置阀门开度成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 限制阀门开度
     * @param valveIds 阀门信息
     * @param hex 阀门开度值
     * @return
     * @throws Exception
     */
    @Override
    public String limitInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "09";
            //计算校验码
            int ll = NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + hex + " 00 00 00 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "限制阀门开度");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(!result.equals("00")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 限制阀门开度失败");
            }else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 限制阀门开度成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，限制阀门开度失败！共 " + failureNum + " 条阀门限制开启失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部限制开启成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 读取阀门数据
     * @param valveIds 阀门信息
     * @return
     * @throws Exception
     */
    @Override
    public String checkInfo(String[] valveIds) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "01";
            //计算校验码
            int ll = NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " 00 00 00 00 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "读取阀门数据");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(!result.equals("00")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 读取失败");
            }else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 读取成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，阀门读取失败！共 " + failureNum + " 条阀门读取失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门数据读取成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
    /**
     * 设置阀控温上限值
     * @param valveIds 阀门信息
     * @param hex 阀控温上限值
     * @return
     * @throws Exception
     */
    @Override
    public String tempmaxInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "1A";
            //指令
            String contc = "06";
            //寄存器
            String jcq = "04";

            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " "+ contc + " "+ jcq + " 00 " + hex + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "设置阀门阀控温上限值");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 设置阀控温上限值失败");
            }else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 设置阀控温上限值成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，设置阀控温上限值失败！共 " + failureNum + " 条设置阀控温上限值失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部设置阀控温上限值成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
    /**
     * 设置阀门开度最大值
     * @param valveIds 阀门信息
     * @param hex 阀门开度值最大值
     * @return
     * @throws Exception
     */
    @Override
    public String aperturemaxInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }


            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "1A";
            String contc = "06";
            //寄存器
            String jcq = "03";

            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + contc + " " + jcq + " 00 " + hex + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "设置阀门开度最大值");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 设置阀门开度最大值失败");
            }else if(result.equals("FF")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 阀门开度最大值小于阀门开度最小值，请重新输入");
            }
            else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、采集器 " + info.getValveId()  + " 设置阀门开度最大值成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，设置阀门开度最大值失败！共 " + failureNum + " 条设置阀门最大值失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部设置阀门开度最大值成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
    /**
     * 设置阀门开度最小值
     * @param valveIds 阀门信息
     * @param hex 阀门阀门开度最小值
     * @return
     * @throws Exception
     */
    @Override
    public String apertureminInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }


            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "1A";
            String contc = "06";
            //寄存器
            String jcq = "02";

            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + contc + " " + jcq + " 00 " + hex + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "设置阀门开度最小值");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);

            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 设置阀门开度最小值失败");
            }else if(result.equals("FF")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 阀门开度最小值大于阀门开度最大值，请重新输入");
            }
            else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、采集器 " + info.getValveId()  + " 设置阀门开度最小值成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，设置阀门开度最小值失败！共 " + failureNum + " 条设置阀门最小值失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部设置阀门开度最小值成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
    /**
     * 阀门回水温度控制使能
     * @param valveIds 阀门信息
     * @param operName 操作用户
     * @return
     * @throws Exception
     */
    @Override
    public String outletonInfo(String[] valveIds, String operName) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            valveId= valveId.substring(valveId.length()-4);
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);

            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);

            //控制码
            String cont = "1A";
            String contc = "06";
            //寄存器
            String jcq = "02";
            //寄存器
            String hex = "01";

            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + contc + " " + jcq + " 00 " + hex + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");

            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "回水温度控制使能");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 阀门回水温度控制使能失败");
            }
            else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、采集器 " + info.getValveId()  + " 阀门回水温度控制使能成功");
            }
        }

        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，阀门回水温度控制使能失败！共 " + failureNum + " 条阀门回水温度控制使能失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部回水温度控制使能成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
    /**
     * 阀门回水温度控制关闭
     * @param valveIds 阀门信息
     * @param operName 操作用户
     * @return
     * @throws Exception
     */
    @Override
    public String outletoffInfo(String[] valveIds, String operName) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            valveId= valveId.substring(valveId.length()-4);
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "1A";
            String contc = "06";
            //寄存器
            String jcq = "06";
            //寄存器
            String hex = "00";
            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hex);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " " + contc + " " + jcq + " 00 " + hex + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");

            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "阀门回水温度控制关闭");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、采集器 " + info.getValveId()  + " 阀门回水温度控制关闭失败");
            }
            else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、采集器 " + info.getValveId()  + " 阀门回水温度控制关闭成功");
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，阀门阀门回水温度控制关闭失败！共 " + failureNum + " 条阀门阀门回水温度控制关闭失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部阀门回水温度控制关闭成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    /**
     * 设置阀门回水温度
     * @param valveIds 阀门信息
     * @param hex 回水温度
     * @return
     * @throws Exception
     */
    @Override
    public String outletInfo(String[] valveIds, String hex) throws InterruptedException {
        int failureNum = 0;
        int successNum = 0;
        StringBuilder failureMsg = new StringBuilder();
        StringBuilder successMsg = new StringBuilder();
        for(String valveId : valveIds){
            ValveInfo info = null;

            if(redisUtil.hHasKey("valve-info", valveId)){
                info = (ValveInfo) redisUtil.hget("valve-info", valveId);
            }else{
                info = valveInfoMapper.selectValveInfoById(valveId);
                redisUtil.hset("valve-info", valveId, info, 60000);
            }

            if(info.getCollectorId() == null || info.getCollectorId().equals("")){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 未关联采集器");
                continue;
            }

            //判断采集器是否在线
            boolean status = redisUtil.hHasKey("sys-netty", info.getCollectorId());
            if(!status){
                failureNum++;
                CollectorInfo cinfo = collectorInfoMapper.selectCollectorInfoById(info.getCollectorId());
                cinfo.setOnlineStatus(Integer.valueOf(0));
                cinfo.setCollectorId(info.getCollectorId());
                collectorInfoMapper.updateById(cinfo);
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + "关联的采集器" + info.getCollectorId() + " 已离线");
                continue;
            }
            //获取采集器高位
            String cenhigh = info.getCollectorId().substring(0,2);
            //获取采集器低位
            String cenlow = info.getCollectorId().substring(2,4);
            valveId= valveId.substring(valveId.length()-4);
            //阀门高位
            String high = valveId.substring(0,2);
            //阀门地位
            String low = valveId.substring(2,4);
            //控制码
            String cont = "1A";
            //指令
            String contc = "06";
            //寄存器
            String jcq = "05";

            //获取采集器高位
            String hexhigh = "0" + hex.substring(0,1);
            //获取采集器低位
            String hexlow = hex.substring(1,3);

            //计算校验码
            int ll = NettyUtil.get10HexNum(contc)+NettyUtil.get10HexNum(jcq)+NettyUtil.get10HexNum(cenhigh)+NettyUtil.get10HexNum(cenlow)+NettyUtil.get10HexNum(high)+NettyUtil.get10HexNum(low)+NettyUtil.get10HexNum(cont)+NettyUtil.get10HexNum(hexhigh)+NettyUtil.get10HexNum(hexlow);
            String check = NettyUtil.get16HexNum(ll);
            if(check.length()<2){
                check = "0" + check;
            }else{
                check = check.substring(check.length()-2);
            }
            String response = "AA " + cenlow + " " + cenhigh + " 00 00 " + low + " " + high + " " + cont + " "+ contc + " "+ jcq + hexhigh + hexlow + " 00 00 " + check + " FF ";
            String responseStr = response.replace(" ", "");
            rabbitUtils.writeToClient(info.getCollectorId(), responseStr, "设置阀门回水温度");
            CountDownLatch countDownLatch = new CountDownLatch(1);
            new Thread(new RedisRun(countDownLatch, redisUtil, valveId, cont)).start();
            countDownLatch.await();
            String result = RedisRun.result;
            redisUtil.del(valveId);
            if(result==null || result.equals("") ){
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、阀门 " + info.getValveId() + " 设置阀回水温度失败");
            }else{
                successNum++;
                successMsg.append("<br/>" + successNum + "、阀门 " + info.getValveId() + " 设置阀回水温度成功"
                       );
            }
        }
        if(failureNum>0){
            failureMsg.insert(0, "很抱歉，设置回水温度失败！共 " + failureNum + " 条设置阀回水温度失败，错误如下：");
            throw new BusinessException(failureMsg.toString());
        }else{
            successMsg.insert(0, "恭喜您，阀门已全部设置阀回水温度成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }
}
